package mysql

import (
	"github.com/go-xorm/xorm"
	"note/service/repository"
)

type ordersRepository struct {
	db *xorm.Engine
}

func NewOrdersRepository(db *xorm.Engine) repository.OrdersRepository {
	return &ordersRepository{db: db}
}

func (self *ordersRepository) InsertOne(doc *repository.Orders) (id int64, err error) {
	return self.db.InsertOne(doc)
}

func (self *ordersRepository) FindById(filter interface{}) (*repository.Orders, error) {
	doc := &repository.Orders{}
	_, err := self.db.Where("order_id=?", filter).Get(doc)
	return doc, err
}

func (self *ordersRepository) Sql(sql string) ([]*repository.Orders, error) {
	var docs []*repository.Orders
	err := self.db.SQL(sql).Find(&docs)
	return docs, err
}
